//
//  CellForCollect.m
//  echo
//
//  Created by dllo on 16/3/3.
//  Copyright © 2016年 Danny. All rights reserved.
//

#import "CellForCollect.h"
#import <SDWebImage/UIButton+WebCache.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import "ModelOfCellForMyExploreTableViewSectionThreeAndFour.h"

@implementation CellForCollect

- (void)dealloc{
    [_modelForCollect release];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"alreadyDeleteForCollect" object:nil];
    [super dealloc];
}

- (void)passDataForCollect:(ModelOfCellForMyExploreTableViewSectionThreeAndFour *)model{
    self.modelForCollect = [[ModelOfCellForMyExploreTableViewSectionThreeAndFour alloc]init];
    self.modelForCollect = model;
    [self.button sd_setBackgroundImageWithURL:[NSURL URLWithString:model.avatar] forState:UIControlStateNormal];
    [self.imageViewOfFamous sd_setImageWithURL:[NSURL URLWithString:model.famous_icon]];
    self.labelForTop.text = model.name;
    self.labelForBottom.text = model.content;
    [self.buttonForDelete addTarget:self action:@selector(handleDeleteForCollect) forControlEvents:UIControlEventTouchUpInside];
}

- (void)handleDeleteForCollect{
    [self.delegateForCollect handleDeleteAlert:self.modelForCollect.name];
    [[NSNotificationCenter defaultCenter] addObserverForName:@"alreadyDeleteForCollect" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
        self.buttonForCollect.hidden = NO;
        self.buttonForDelete.hidden = YES;
    }];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.buttonForCollect.hidden = YES;
    self.buttonForDelete.hidden = NO;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
